#!/bin/bash
#
# Translations from EGEE scheduler names to scheduler class types
#
# Author:   Mike Murphy <mamurph@cs.clemson.edu>
# Revision: 23 September 2009
#
#   Copyright 2009 Clemson University
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#
# This material is based upon work supported under a National Science
# Foundation Graduate Research Fellowship. Any opinions, findings,
# conclusions or recommendations expressed in this publication are those of
# the author(s) and do not necessarily reflect the views of the National
# Science Foundation.

'''
Scheduler name translator for schedulers found on the Enabling Grids for
E-sciencE (EGEE) grid system, as reported in data obtained from the
Grid Observatory (U{http://grid-observatory.org}).
'''


from condor_sim import Condor
from control_scheduler import ControlScheduler
from scheduler import Scheduler


SCHED_MAP = { 'condor': Condor, 'lcgcondor': Condor, \
              '_control_' : ControlScheduler }
#

def new_egee_scheduler(egee_name, site_name, simobj, *args, **kwds):
   '''
   Translates a scheduler name into an instance of the corresponding scheduler,
   with the special name "_control_" used to instantiate a ControlScheduler.
   If a scheduler name is unknown to this function, a generic Scheduler
   instance will be returned.

   @param egee_name: Name of the scheduler as used in EGEE GRIF-LAL data
   @type egee_name: str
   @param site_name: Site name where the scheduler will be located
   @type site_name: str
   @param simobj: Reference to the simulator instance
   @param args: Arguments to be passed to the simulator constructor
   @param kwds: Keywords to be passed to the simulator constructor

   @return: Scheduler (or subclass) instance
   '''
   sched = None
   if egee_name in SCHED_MAP:
      sched = SCHED_MAP[egee_name](simobj, tag=site_name, *args, **kwds)
   else:
      sched = Scheduler(simobj, name=egee_name, tag=site_name, *args, **kwds)
   return sched
#
